import React from "react";
import { Navigate, useLocation } from "react-router-dom";
// 导入ReactNode类型
import { FC, ReactNode } from "react";

interface Iprops {
  children?: ReactNode
}

// 定义一个函数Private是FC类型 指令泛型为Iprops
const Private: FC<Iprops>=(props) => {
  var token = sessionStorage.getItem("token")
  const location = useLocation()
  if (token) {
    return <>{props.children}</>
  } else {
    // 跳转首页，添加redirect查询参数
    return <Navigate to={'/?redirect' + location.pathname}></Navigate>
  }
}

export default Private